package com.study.rabbitmq2.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.study.rabbitmq2.util.ConnectionUtil;

/**
 * @Author chenyeqing
 * @Date 2021/11/21 16:45
 */
public class Send {
    private final static String EXCHANGE_NAME = "test_fanout_exchange";

    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        // 声明交换机 类型指定为 fanout
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        // 消息内容
        String msg = "注册成功！";

        // 发送消息到交换机
        channel.basicPublish(EXCHANGE_NAME, "", null, msg.getBytes());
        System.out.println("[生产者] Send: " + msg);

        channel.close();
        connection.close();
    }
}
